function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	  // Internet Explorer
	  try{
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e){
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}

// function writediv(texte, box){
// 	if($(box)) $(box).innerHTML = texte;
// }

function adddiv(texte, box){
		if($(box)) $(box).innerHTML = $(box).innerHTML + texte;
}

function popupform(myform, windowname)
{
if (! window.focus)return true;
	window.open('', windowname, 'height=100,width=200,scrollbars=no');
	myform.target=windowname;
	return true;
}


function file(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
	xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
	xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
	else
	return(false);
	xhr_object.open('GET', fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4){
		return(xhr_object.responseText);
	}
	else return(false);
}

// if(window.writediv == null){
//   function writediv(texte, box){
// 		var parentElement = $(box);
// 		try {
// 		  parentElement.innerHTML = texte;
// 		}
// 		catch (e) {
// 		  // // IE fails unless we wrap the string in another element.
// 		  // wrappingDiv = document.createElement('div');
// 		  // wrappingDiv.innerHTML = texte;
// 		  // parentElement.appendChild(wrappingDiv);
// 		}
// 	}
// }

function writediv(texte,box){
	if($(box)) $(box).innerHTML = texte;
}

function navigation(){
	texte = file('navigation.php');
	if(texte){
		writediv(texte,'navigation');
	}
}



function perso(){
	text = file('perso.php');
	if(text) {
		var tab = text.split("<!---->");
		writediv(tab[0],'perso');
		if(tab[1]) writediv(tab[1],'logout');
		if(tab[2]) writediv(tab[2],'bienvenue');
	}
}

function logout(){
	text = file('perso.php?action=del');
	writediv(text,'perso');
	writediv('','logout');
	writediv('invit&eacute;','bienvenue');
	self.location.reload();
}

function identify(nom,ddn){
	text = file('perso.php?action=submit&nom='+nom+'&ddn='+ddn);
	if(text) {
		var tab = text.split("<!---->");
		if(tab[0].match('KO')){
			message("Identitication &eacute;chou&eacute;e");
			writediv(tab[1],'perso');
		}
		else{
			// writediv(tab[0],'perso');
			self.location.reload();
		}
	}
}

function liste_infos(start,nb,id_info){
	if(!nb) nb = 1;
	if(!id_info) id_info = '';
	texte = file('get_infos.php?nb='+nb+'&id='+id_info+'&start='+start)
	if(texte){
		tableau = texte.split("<!--!>")
		if(!id_info){
			if(tableau[0]){
				$('previous').style.display = 'block'
				$('previous').style.visibility = 'visible'
				writediv(tableau[0],'previous')
			}
			else{
				$('previous').style.display = 'none'
				$('previous').style.visibility = 'hidden'
			}
			if(tableau[1]){
				$('next_info').style.display = 'block'
				$('next_info').style.visibility = 'visible'
				writediv(tableau[1],'next_info')
			}
			else{
				$('next_info').style.display = 'none'
				$('next_info').style.visibility = 'hidden'
			}
		}
		writediv(tableau[2],'infos')
	}
	else writediv('','infos')
}

function edit_comment(info_id,comment_id){
	if(info_id && comment_id){
		texte = file('get_commentaires_info.php?id='+info_id+"&action=form&comment="+comment_id);
		if(texte){
			writediv(texte,'commentaire_'+comment_id);
		}
		else{
			writediv('','commentaire_'+comment_id);
		}
	}
}

function edit_commentaire(comment_id,comment){
	if(comment_id && comment){
		texte = file("get_commentaires_info.php?action=edit&comment="+comment_id+"&contenu="+escape(comment));
		if(texte){
			writediv(texte,'commentaire_'+comment_id);
		}
		else{
			writediv('','commentaire_'+comment_id);
		}
	}
}

function del_comment(comment){
	if(comment){
		texte = file("get_commentaires_info.php?action=del&comment="+comment);
		if(texte){
			writediv(texte,'commentaire_'+comment);
		}
		else{
			writediv('','commentaire_'+comment);
		}
	}
}
function del_comment_ok(comment,ok){
	if(comment){
		texte = file("get_commentaires_info.php?action=del&comment="+comment+"&confirm="+ok);
		if(texte && ok==1){
			liste_commentaires_info(texte);
		}
		else{
			writediv(texte,'commentaire_'+comment);
		}
	}
}


function liste_commentaires_info(info_id){
	if(info_id){
		texte = file('get_commentaires_info.php?id='+info_id);
		if(texte){
			writediv(texte,'commentaires');
		}
		else{
			writediv('','commentaires');
		}
	}
}

function liste_communications(equipe){
	if(equipe){
		texte = file('get_communications.php?id='+equipe);
		if(texte){
			writediv(texte,'communications');
		}
		else{
			writediv('','communications');
		}
	}
}


function message(leMessage,succes){
	if(leMessage.indexOf('effectu') != -1 || leMessage.indexOf('succ') != -1 || leMessage.indexOf('ussie') != -1 || succes == 1) $('message').className = "succes";
	$('message').style.visibility = 'visible';
	$('message').style.display = 'inline';
	writediv(leMessage,'message');
	setTimeout("$('message').style.visibility = 'hidden';$('message').style.display = 'none';",2000);

}

function ajout_commentaire(myform){
	if(myform){
		var membre = myform.membre.value;
		var contenu = myform.contenu.value;
		var mytype = myform.mytype.value;
		var id_info = myform.id_info.value;
		contenu = contenu.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br />");
		texte = file('ajout_commentaire.php?type='+mytype+'&membre='+membre+'&contenu='+contenu+'&id_info='+id_info);
		if(texte == 'ok'){
			liste_commentaires_info(myform.id_info.value);
		}
		else{
			message("D&eacute;sol&eacute;, le commentaire n&#39;a pas &eacute;t&eacute; ajout&eacute;<br />"+texte);
		}
	}
}
function ajout_communication(membre,contenu,equipe,email){
	if(membre && contenu && equipe){
		contenu = contenu.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br />");
		texte = file('ajout_communication.php?membre='+membre+'&contenu='+contenu+'&equipe='+equipe+'&email='+email);
		if(texte == 'ok'){
			message("Message ajout&eacute;");
			liste_communications(equipe);
		}
		else{
			message("D&eacute;sol&eacute;, la communication n&#39;a pas &eacute;t&eacute; ajout&eacute;e<br />"+texte);
		}
	}
}

function check_communications(){
	text = file('communications.php');
	if(text){
		writediv(text,'center_box');
		center_box(1,600,'1');
	}
}

function valide_communications(){
	var all_comm = "";
	for(var i = 0; i < document.form_communications.elements.length; i++){
		var el = document.form_communications.elements[i];
		all_comm += el.name+"_";
	}
	if(all_comm.length) file('communications.php?valide='+all_comm);
	center_box(0);
}

function list_communications(){
	text = file('communications.php?action=list');
	if(text){
		writediv(text,'center_box');
		center_box(1,600,'1');
	}
}

function insertcode(tag,textarea)
{
	var zorglub
	//IE support
	if (document.selection) {
		textarea.focus();
		sel = document.selection.createRange();
		contenu=sel.text

		if(contenu == "" || contenu == null){
			zorglub=1
		}

		if(zorglub!=1)
		{
			sel.text = contenu+tag;
		}
		else
		{
			textarea.value+=contenu+tag;
		}

	}
	//MOZILLA/NETSCAPE support
	else if (textarea.selectionStart || textarea.selectionStart == '0') {
		var startPos = textarea.selectionStart;
		var endPos = textarea.selectionEnd;
		var contenu = textarea.value.substring(startPos, endPos)

		if(contenu == "" || contenu == null){
			zorglub=1
		}

		if(zorglub!=1 || startPos!=0)
		{
			textarea.value = textarea.value.substring(0, startPos) + contenu + tag + textarea.value.substring(endPos, textarea.value.length);
		}
		else
		{
			textarea.value+=contenu+tag;
		}
	}
}

function inserttag(tag,textarea)
{
	var zorglub
	//IE support
	if (document.selection) {
		textarea.focus();
		sel = document.selection.createRange();
		contenu=sel.text

		if(contenu == "" || contenu == null){
			contenu = prompt("Texte:", "")
			zorglub=1
		}

		if(contenu == null) return

		if(contenu == ""){
			contenu = "texte"
		}

		if(zorglub!=1)
		{
			sel.text = tag+contenu+tag;
		}
		else
		{
			textarea.value+=tag+contenu+tag;
		}

	}
	//MOZILLA/NETSCAPE support
	else if (textarea.selectionStart || textarea.selectionStart == '0') {
		var startPos = textarea.selectionStart;
		var endPos = textarea.selectionEnd;
		var contenu = textarea.value.substring(startPos, endPos)

		if(contenu == "" || contenu == null){
			contenu = prompt("Texte:", "")
			zorglub=1
		}

		if(contenu == null) return

		if(contenu == ""){
			contenu = "texte"
		}

		if(zorglub!=1 || startPos!=0)
		{
			textarea.value = textarea.value.substring(0, startPos) + tag + contenu + tag + textarea.value.substring(endPos, textarea.value.length);
		}
		else
		{
			textarea.value+=tag+contenu+tag;
		}
	}
}
function get_info(id_info){
	if(!id_info) id_info = '';
	if($('info_'+id_info)){
			writediv("",'liste_info_'+id_info);
	}
	else{
		texte = file('get_infos.php?id='+id_info)
		if(texte){
			tableau = texte.split("<!--!>");
			if(tableau.length > 1)	writediv(tableau[2],'center_box')
			else writediv(texte,'center_box');
			self.location.href = '#top';
			center_box(1,600,1);
		}
		else{
			writediv("",'liste_info_'+id_info);
		}
	}
}
function show_corps_info(info_id){
	if(info_id){
		texte = file("get_infos.php?corps="+info_id)
		if(texte){
			writediv(texte,'info_'+info_id);
		}
		else writediv('','info_'+info_id);
	}
	else writediv('','info_'+info_id);
}

function show_info(info_id){
	if(info_id){
		if($('info_'+info_id).style.visibility == 'hidden'){
			show_corps_info(info_id);
			$('info_'+info_id).style.visibility = 'visible';
			$('info_'+info_id).style.display = 'inline';
		}
		else{
			text = file('get_infos.php?id='+info_id+'&hide=1');
			writediv(text,'liste_info_'+info_id);
		}
	}
}


function preview(texte,div_id){
	var nl = new RegExp("\n","g");
	texte = texte.replace(nl,"<br />");
	new Ajax.Request('prepare_info.php',
	   {
	     method:'post',
	     parameters: {texte: texte},
	     onSuccess: function(transport){
	         var div_content = transport.responseText || "no response text";
			writediv(div_content,div_id);
	     },
	     onFailure: function(){ message('Something went wrong...') }
	   });
}


function list_activites(start){
	text = file('activites_admin.php?action=list&start='+start);
	if(text) writediv(text,'action');
}


function list_infos(start){
	text = file('infos_admin.php?action=list&start='+start);
	if(text) writediv(text,'action');
}

function list_historique(start){
	text = file('historique_admin.php?action=list&start='+start);
	if(text) writediv(text,'action');
}


function list_brefs(start){
	text = file('brefs_admin.php?action=list&start='+start);
	if(text) writediv(text,'action');
}

function new_bref(){
	text = file('brefs_admin.php?action=new');
	if(text) writediv(text,'action');
}

function del_bref(id){
	text = file('brefs_admin.php?action=del&id='+id);
	if(text) message(text);
	list_brefs();
}

function edit_bref(id_bref){
	text = file("brefs_admin.php?action=new&id="+id_bref)
	if(text) writediv(text,'action');
	preview(document.myform.contenu.value,"preview");
}

function new_activite(){
	text = file('activites_admin.php?action=new');
	if(text) writediv(text,'action');
	new Ajax.Autocompleter('membre', 'autocomplete_choices', 'verif_membre.php', {paramName: 'value', minChars: 2, indicator: 'indicator_responsable', afterUpdateElement: check_name});

}

function del_activite(id){
	text = file('activites_admin.php?action=del&id='+id);
	if(text) message(text);
	list_activites();
}

function edit_activite(id_activite){
	text = file("activites_admin.php?action=new&id="+id_activite)
	if(text) writediv(text,'action');
	new Ajax.Autocompleter('membre', 'autocomplete_choices', 'verif_membre.php', {paramName: 'value', minChars: 2, indicator: 'indicator_responsable', afterUpdateElement: check_name});

}


function new_info(){
	new Ajax.Updater('action',"infos_admin.php",{
		parameters: {action: 'new'},
	});
}

function del_info(id){
	text = file('infos_admin.php?action=del&id='+id);
	if(text) message(text);
	list_infos();
}

function edit_info(id_info){
	text = file("infos_admin.php?action=new&id="+id_info)
	if(text) writediv(text,'action');
}

function new_historique(){
	text = file('historique_admin.php?action=new');
	if(text) writediv(text,'action');
}


function del_historique(id){
	text = file('historique_admin.php?action=del&id='+id);
	if(text) message(text);
	list_historique();
}

function edit_historique(id_historique){
	text = file("historique_admin.php?action=new&id="+id_historique)
	if(text) writediv(text,'action');
}

function list_salles(my_order){
	text = file("salles_admin.php?action=list&order="+my_order);
	if(text) writediv(text,'action');
}

function new_salle(){
	text = file("salles_admin.php?action=new");
	if(text) writediv(text,'action');
}

function edit_salle(myid){
	text = file("salles_admin.php?action=edit&id="+myid);
	if(text) writediv(text,'action');
}

function verif_nosalle(no){
	text = file("salles_admin.php?action=checkno&id="+no);
	if(text == 1) {
		writediv("Ce num&eacute;ro est d&eacute;j&agrave; attribu&eacute; !!","check_no");
		document.myform.no.value = "";
		document.myform.no.focus();
	}
}

function del_salle(doc_id){
	text = file("salles_admin.php?action=delete&id="+doc_id)
	if(text) message(text);
	list_salles('');
}

function list_partenaires(valide){
	new Ajax.Updater('action','partenaires_admin.php',{parameters: {action: 'list',filter: valide}});
}

function new_partenaire(){
	new Ajax.Updater('action','partenaires_admin.php',{parameters: {action: 'new'},onComplete: function(){
		new Ajax.Updater('contrats','partenaires_admin.php',{
			parameters: {id: '',action: 'print_contrats'}
		})		
	}});
}

function edit_partenaire(myid){
	new Ajax.Request('partenaires_admin.php',{
		parameters: {action: 'edit',id: myid},
		onComplete: function(transport){
			var response = transport.responseText || "";
			$('action').update(response);
			new Ajax.Updater('contrats','partenaires_admin.php',{
				parameters: {id: myid,action: 'print_contrats'}
			})
		}
	})
}


function new_contrat(partenaire_id){
	if(!$('new_cat_id').getValue()){
		message("Veuillez choisir un type de soutien")
		return
	}
	if(!$('new_quantite').getValue()){
		message("Veuillez choisir une quanite")
		return		
	}
	if(!$('new_prix').getValue()){
		message("Veuillez choisir un prix")
		return		
	}
	new Ajax.Request('partenaires_admin.php',{
		parameters: {action: 'add_contrat',id: partenaire_id,quantite: $('new_quantite').getValue(), prix: $('new_prix').getValue(), cat_id: $('new_cat_id').getValue(),valide: $('new_valide').getValue(),paye: $('new_paye').getValue()},
		onComplete: function(transport){
			var response = transport.responseText || ""
			message(response);
			new Ajax.Updater('contrats','partenaires_admin.php',{
				parameters: {id: partenaire_id,action: 'print_contrats'}
			})
			
		}
	})
}


function supprimer_contrat(soutien_id,partenaire_id){
	if(confirm('confirmer la suppression du contrat ?')){
		new Ajax.Request('partenaires_admin.php',{
			parameters: {action: 'delete_contrat',id: soutien_id},
			onComplete: function(transport){
				var response = transport.responseText || "";
				message(response);
				new Ajax.Updater('contrats','partenaires_admin.php',{
					parameters: {id: partenaire_id,action: 'print_contrats'}
				})				
				
			}
		})
	}
}


function del_partenaire(doc_id){
	new Ajax.Request('partenaires_admin.php',{
		parameters: {action: 'delete',id: doc_id},
		onComplete: function(transport){
			var response = transport.responseText || "";
			message(response);
			list_partenaires(1);
		}
	})
}

function valide_partenaire(id,value){
	text = file('partenaires_admin.php?action=valide&id='+id+'&value='+value);
	writediv(text,'valide_'+id);
	if(value) message("partenariat validé");
	else message("partenariat suspendu");
}

function list_documents(my_order){
	text = file("documents_admin.php?action=list&order="+my_order);
	if(text) writediv(text,'action');
}

function new_document(){
	text = file("documents_admin.php?action=new");
	if(text) writediv(text,'action');
}

function edit_document(myid){
	text = file("documents_admin.php?action=edit&id="+myid);
	if(text) writediv(text,'action');
}


function del_document(doc_id){
	text = file("documents_admin.php?action=delete&id="+doc_id)
	if(text) message(text);
	list_documents('');
}

function membre_details(membre_id,edit){
	if(edit == 1) text = file("membre_admin.php?action=detail&id="+membre_id);
	else text = file("membre.php?action=detail&id="+membre_id);
	if(text){
		$('membre_details').style.display = 'block';
		$('membre_details').style.visibility = 'visible';
		var tab = text.split("<!---->");
		writediv(tab[0],'nom');
		writediv(tab[1],'details');
	}
}

function list_membres(start,edit,ancien){
	if(!ancien) ancien = 0;
	if(edit) text = file("membre_admin.php?action=list&start="+start+"&ancien="+ancien);
	else text = file("membre.php?action=list&start="+start);
	if(text) writediv(text,'action');
	else writediv('','action');
}

function update_table(start,tablename){
	text = file("update_print_table.php?start="+start+"&tablename="+tablename);
	if(text){
			update_tbody(text,'',tablename);
	}
}

function update_tbody(mytext,tbody_name,tablename){
	if(tbody_name == null || tbody_name == '') tbody_name = 'table_content_'+tablename;
	mytable = $(tbody_name);
	for(var i=mytable.childNodes.length-1; i>=0; i--){
		mytable.removeChild(mytable.childNodes[i]);
	}
	var myrows = mytext.split(/\n\n/);
	for(var j = 0; j < myrows.length; j++){
		var expression = /onclick\ =\ \"(.*?)\"/;
		expression.exec(myrows[j]);
		var tronclick = RegExp.$1;
		var expression = /<tr\ [^>]*class\ =\ \'(.*?)\'/;
		expression.exec(myrows[j]);
		var trclass = RegExp.$1;
		var expression = /<tr\ [^>]*style\ =\ \'(.*?)\'/;
		expression.exec(myrows[j]);
		var trstyle = RegExp.$1;
		var tr  = document.createElement('TR');
		tr.onclick = new Function(tronclick);
		tr.className = trclass;
		tr.setAttribute("style",trstyle);
		mytable.appendChild(tr);
		var mycells = myrows[j].split(/\n/);
		for(var h = 0; h < mycells.length; h++){
			var mytext = mycells[h].replace(/<td.*?>/,"");
			var mytext = mytext.replace(/<tr.*?>/,"");
			var mytext = mytext.replace(/<\/t[rd].*?>/,"");
			var td = document.createElement('TD');
			var expression = /<td\ onclick\ =\ \"(.*?)\"/;
			var tdonclick = (expression.exec(mycells[h])) ? RegExp.$1 : "";
			var expression = /<td\ [^>]*?class\ =\ \'(.*?)\'/;
			var tdclass = (expression.exec(mycells[h])) ? RegExp.$1 : "";
			var expression = /<td\ [^>]*?colspan\ =\ \'(.*?)\'/;
			var tdcolspan = (expression.exec(mycells[h])) ? RegExp.$1 : "";
			var expression = /<td\ [^>]*?id\ =\ \'(.*?)\'/;
			var tdid = (expression.exec(mycells[h])) ? RegExp.$1 : "";
			var expression = /<td\ [^>]*?name\ =\ \'(.*?)\'/;
			var tdname = (expression.exec(mycells[h])) ? RegExp.$1 : "";
			var expression = /<td\ [^>]*?style = \'(.*?)\' /;
			expression.exec(mycells[h]);
			var tdstyle = RegExp.$1;
			var td  = document.createElement('td');
			if(tdonclick) td.onclick = new Function(tdonclick);
			if(tdclass) td.className = tdclass;
			if(tdid) td.setAttribute("id",tdid);
			if(tdname) td.setAttribute("id",tdname);
			if(tdstyle) td.setAttribute("style",tdstyle);
			if(tdcolspan) td.setAttribute("colspan",tdcolspan);
			td.innerHTML = mytext;
			tr.appendChild(td);
		}
	}
}

function sort_table(myvalue,tablename){
	mytext = file("update_print_table.php?value="+myvalue+"&action=sort&tablename="+tablename);
	update_tbody(mytext,'',tablename);
}

function hide_row_table(id,status,col,tablename){
	if(!col) col = 'id';
	text = file("update_print_table.php?id="+id+"&status="+status+"&action=hide&col="+col+"&tablename="+tablename);
	if(text) update_tbody(text,'',tablename);

}

function table_date(myvalue,tablename){
	text = file("update_print_table.php?value="+myvalue+"&action=date&tablename="+tablename);
	if(text) update_tbody(text,'',tablename);
	if(myvalue == -1){
		writediv("<a href = 'javascript:table_date(0,\""+tablename+"\")'>Afficher tous les matchs</a>","table_date");
	}
	else{
		writediv("<a href = 'javascript:table_date(-1,\""+tablename+"\")'>Afficher les prochains matchs</a>","table_date");
	}

}

function table_filter(myvalue,tablename){
	if(window.mytimeout) window.clearTimeout(window.mytimeout); 
	window.mytimeout = window.setTimeout(function(){
		new Ajax.Request('update_print_table.php',{
			parameters: {action: 'filter',value: myvalue,tablename: tablename},
			onComplete: function(transport){
				var text = transport.responseText || "";
				if(text)	update_tbody(text,'',tablename);
				resultat = text.match(/<tr[^>]*onclick *= *['"]([^>]*);?['"]>/ig);
				if(resultat){
					if(resultat.length == 1) eval(RegExp.$1);
				}
			}
		})
	},500)
}

function in_array(needle,myarray){
	for(var i = 0; i < myarray.length; i++){
		if(myarray[i] == needle) return true;
	}
	return false;
}


function setclass(div_id,class_name){
	if($(div_id)) $(div_id).className = class_name;
}

function update_db(table,id,thefield,thevalue,no_output){
	ok = 1;
	if(!thevalue){
		var required = new Array("nom","titre","prenom","adresse","localite","ddn_jour","ddn_mois","ddn_annee","commune");
		if ((','+required.toString()+',').indexOf(','+thefield+',')!=-1){
			message("Vous devez fournir une valeur pour '"+thefield+"'");
			document.myform.elements[thefield].focus();
			text = file("get_table_field.php?table="+table+"&id="+id+"&field="+thefield);
			document.myform.elements[thefield].value = text;
			ok = 0;
		}
	}
	if(ok){
		text = file("update_db.php?table="+table+"&id="+id+"&field="+thefield+"&value="+thevalue);
		if(!no_output) {
			if(text == 1) {writediv("<span class = 'oui'>ok</span>","ok_"+thefield); message("Modification effectuee");}
			else writediv("<span class = 'non'>ko</span>","ok_"+thefield);
		}
	}
}

function add_team(membre,equipe){
	text = file("update_membre_equipe.php?action=add&membre="+membre+"&equipe="+equipe);
	if(text == 1) message("modification effectu&eacute;e");
	else message ("D&eacute;sol&eacute;, une erreur est survenue");
}

function del_team(membre,equipe){
	file("update_membre_equipe.php?action=del&membre="+membre+"&equipe="+equipe);
	if(text == 1) message("modification effectu&eacute;e");
	else message ("D&eacute;sol&eacute;, une erreur est survenue");
}

function center_box(display,width,absolute){
	if(el = $('center_box_content')){
		el2 = $('center_box');
		if(display){
			var close_el = document.createElement('DIV');
			close_el.className = 'close_box';
			close_el.id = 'close_box';
			close_el.onclick = function(){center_box(0);};
			el.style.visibility = 'visible';
			el.style.display = 'block';
			if(width){
				el2.style.width = width+'px';
				var margin = (900 - width) / 2;
				el.style.marginLeft = margin+'px';
			}
			else{
				var margin = (900 - 500) / 2;
				el.style.marginLeft = margin+'px';
			}
			if(absolute) el.style.position = 'absolute';
			else el.style.position = 'fixed';
			el.appendChild(close_el);
			border.render('center_box');
			// writediv('','center_box');
			if(navigator.appName == "Microsoft Internet Explorer"){ el.style.position = 'absolute';el.style.left = 0;	self.location.href = '#top';}
		}
		else{
			el.style.display = 'none';
			el2.innerHTML = '';
			var close_box = $('close_box');
			el.removeChild(close_box);
		}
	}
}

function update_membre_admin(membre,commission,fonction){

	if(fonction== 'new'){
		text = file('update_membre_admin.php?membre='+membre+'&commission='+commission+'&fonction=new')
		writediv(text,'center_box');
		center_box(1);
	}
	else{
		fonction = escape(fonction);
		text = file('update_membre_admin.php?membre='+membre+'&commission='+commission+'&fonction='+fonction);
		var tab = text.split("<!--!>");
		if(tab[0]=='OK'){
			message("Modification effectu&eacute;e");
			writediv(tab[1],"commission_"+commission);
			if($("center_box").style.visibility == 'visible') center_box(0);
		}
		else message("D&eacute;sol&eacute;, une erreur est survenue\n"+tab[1]);
	}
}

function submit_membre_admin(commission){
	$('form_membre_admin').request({
	  method: 'post',
	  onComplete: function(transport){
		var response = transport.responseText || "aucune donn&eacute;e...";
		var tab = response.split("<!--!>");
		if(tab[0]=='OK'){
			message("Modification effectu&eacute;e");
			writediv(tab[1],"commission_"+commission);
			center_box(0);
		}
		else message("D&eacute;sol&eacute;, une erreur est survenue\n"+tab[1]);
	 }
	})

}

function new_membre(){
	text = file('membre_admin.php?action=new');
	if(text) writediv(text,'action');
}

function demission(membre_id,status){
	valide = (status == 1) ? 0 : 1;
	var curdate = new Date;
	var print_date = (status == 1) ? curdate.getFullYear()+"-"+(curdate.getMonth()+1)+"-"+curdate.getDate() : "NULL";
	update_db('membres',membre_id,'valide',valide,1);
	update_db('membres',membre_id,'demission',print_date,1);
	if(status == 1) file("membre_admin.php?action=demission&id="+membre_id);
	hide_row_table(membre_id,1);
	if(status == 1) message("Membre d&eacute;mission&eacute; avec succ&eacute;s");
	else message("Membre r&eacute;int&eacute;gr&eacute; avec succ&eacute;s");
}

function form_membre_check(myform){
	if(myform){
		var missing = "";
		var required = new Array("titre","nom","prenom","adresse","localite");
		var req_number = new Array("npa","ddn_jour","ddn_mois","ddn_annee");
		for(var i = 0; i < required.length; i++){
			var champ = required[i];
			if(!myform.elements[champ].value) missing += champ+" ne peut pas être vide\n";
			myform.elements[champ].focus();
		}
		for(var i = 0; i < req_number.length; i++){
			var champ = req_number[i];
			var re = new RegExp("[^0-9]");
			if(!myform.elements[champ].value) missing += champ+" ne peut pas être vide\n";
			else if(myform.elements[champ].value.match(re)) missing += champ+" doit être un nombre\n";
			myform.elements[champ].focus();
		}
		if(!myform.elements['tel'].value && !myform.elements['mobile'].value) missing += "Vous devez fournir un numéro de téléphone fixe ou mobile\n";
		if(missing){
			alert(missing);
			return false
		}
		else return true;
	}
	else return false
}

function activites(id){
	if(id){
		text = file("activites.php?id="+id);
		writediv(text,'action');
	}
}

function inscription_activite(){
	$('myform').request({
	  method: 'post',
	  onComplete: function(transport){
		var response = transport.responseText || "aucune donn&eacute;e...";
		var tableau = response.split("<--->");
		writediv(tableau[0],"inscrits");
		message(tableau[1]);
	 }
	})

}

function inscription(step,membre_id){
	if(step){
		if(step == 2) new_membre();
		else{
			text =(step==4) ? file("inscriptions.php?step="+step+"&id="+membre_id) : file("inscriptions.php?step="+step);
			if(text){
				writediv(text,'action');
			}
			else writediv('','action');
		}
	}
}

function equipe_detail(id_eq){
	if(id_eq){
		self.location.href = "#top";
		text = file("equipes.php?id="+id_eq+"&entete=1");
		if(text) writediv(text,'body');
	}
}

function show_el(my_id){
	if(el = $(my_id)){
		el.style.display = 'inline';
		el.style.visibility = 'visible';
	}
}

function hide_el(my_id){
	if(el = $(my_id)){
		el.style.display = 'none';
		el.style.visibility = 'hidden';
	}
}

function show_photos_equipe(id_equipe,status_photo){
	text = file("equipes.php?id="+id_equipe+'&photo='+status_photo);
	writediv(text,'membres_equipe');
}

function show_membre(membre_id,marquage,arbitrage){
	text = file("membre.php?id="+membre_id+"&action=detail&box=2&marquage="+marquage+"&arbitrage="+arbitrage);
	// text += "<p class = 'center'><a href = 'javascript:center_box(0)'>fermer</a></p>\n";
	writediv(text,'center_box');
	center_box(1,500);
}

function change_saison(equipe,saison){
	text_saison = file("equipes.php?id="+equipe+"&saison="+saison);
	if(text) writediv(text_saison,'stats_equipe');
}

function show_change_saison(myvalue){
	el1 = $('choix_saison');
	el2 = $('saison_actuelle');
	if(myvalue){
		el1.style.display = 'inline';
		el1.style.visibility = 'visible';
		el2.style.display = 'none';
		el2.style.visibility = 'hidden';
	}
	else{
		el2.style.display = 'inline';
		el2.style.visibility = 'visible';
		el1.style.display = 'none';
		el1.style.visibility = 'hidden';
	}
}

function del_communication(com_id){
	text = file("communications.php?id="+com_id+"&action=del");
	if(text == 1){
		el = $('communication_'+com_id);
		if(el){
			el.style.display = 'none';
			el.style.visibility = 'hidden';
		}
		else alert(el);
	}
}

var newwindow = ''
function popitup(url,height,width) {
if (newwindow.location && !newwindow.closed) {
    newwindow.location.href = url;
    newwindow.focus(); }
else {

newwindow=window.open(url,'popupvbcll',"toolbar=0,location=0,directories=0,status=0, scrollbars=0,resizable=0,menubar=0,top=10,left=10,width="+width+",height="+height);}

}

function popitup(url, height, width) {
	newwindow=window.open(url,'name',"toolbar=0,location=0,directories=0,status=0, scrollbars=0,resizable=0,menubar=0,top=10,left=10,width="+width+",height="+height);
	if (window.focus) {newwindow.focus()}
	// return false;
}

function liste_equipes(){
	text = file('equipes_admin.php?action=list');
	writediv(text,'action');
	// Sortable.create('table_content',{tag:'tr',onUpdate:rank_equipes,});
}

function rank_equipes(){
	var options = {
	                method : 'post',
	                parameters : Sortable.serialize('table_content')
	              };
	new Ajax.Request('equipes_admin.php?action=rank', options);

}

function change_nom_equipe(){
	$("form_nom_equipe").request({
		method: 'post',
		parameters: {action: 'nom_equipe'},
		onComplete: function(transport){
			var response = transport.responseText || 0;
			if(response){
				var tab = response.split("<!--!>");
				hide_row_table(1,0,"id","nom_equipe");
				hide_row_table(10,1,"id","nom_equipe");
				writediv(tab[0],"form_nom");
				writediv(tab[1],"form_nom_complet");
			}
	 	}
	});
}

function edit_equipe(id_equipe){
	text = file('equipes_admin.php?action=edit&id='+id_equipe);
	writediv(text,'action');
	list_entrainements(id_equipe);
	list_responsables(id_equipe);
	list_joueurs(id_equipe);
}
//
function delete_equipe(id_equipe){
	center_box(1,600);
	text = file('equipes_admin.php?action=delete&id='+id_equipe);
	writediv(text,'center_box');
}

function confirm_delete_equipe(id_equipe){
	center_box(0);
	text = file('equipes_admin.php?action=delete&confirm=1&id='+id_equipe);
	message(text);
	liste_equipes();
}

function list_entrainements(id){
	text = file("entrainements_admin.php?equipe="+id);
	writediv(text,'entrainements');
}

function form_edit_entrainement(id){
	text = file("entrainements_admin.php?id="+id);
	if(text){
		var tab = text.split("<!--!>");
		var jour = tab[0];
		var heure = tab[1];
		var salle = tab[2];
		var match = tab[3];
		var myaction = tab[4];
		writediv(jour,"jour_"+id);
		writediv(heure,"heures_"+id);
		writediv(salle,"salle_"+id);
		writediv(match,"match_"+id);
		writediv(myaction,"action_"+id);
	}
}

function edit_entrainement(id,jour,hd,md,hf,mf,salle,match){
	text = file("entrainements_admin.php?id="+id+"&jour="+jour+"&hd="+hd+"&md="+md+"&hf="+hf+"&mf="+mf+"&salle="+salle+"&match="+match);
	if(text){
		if(id == 'new'){
			list_entrainements(text);
		}
		else{
			var tab = text.split("<!--!>");
			var jour = tab[0];
			var heure = tab[1];
			var salle = tab[2];
			var match = tab[3];
			var myaction = tab[4];
			writediv(jour,"jour_"+id);
			writediv(heure,"heures_"+id);
			writediv(salle,"salle_"+id);
			writediv(match,"match_"+id);
			writediv(myaction,"action_"+id);
		}
	}
}

function delete_entrainement(id){
	text = file("entrainements_admin.php?id="+id+"&del=1");
	list_entrainements(text);
}

function list_responsables(id){
	text = file("responsables_admin.php?equipe="+id);
	writediv(text,'responsables');
}

function form_edit_responsable(id,equipe_id){
	text = file("responsables_admin.php?id="+id+"&equipe_id="+equipe_id);
	if(text){
		var tab = text.split("<!--!>");
		var membre = tab[0];
		var fonction = tab[1];
		var myaction = tab[2];
		writediv(membre,"membre_"+id);
		writediv(fonction,"fonction_"+id);
		writediv(myaction,"actionresp_"+id);
	}
	new Ajax.Autocompleter('membre', 'autocomplete_choices', 'verif_membre.php', {paramName: 'value', minChars: 2, indicator: 'indicator1', afterUpdateElement: check_name});
}

function new_responsable(equipe_id,membre_id,fonction){
	file("responsables_admin.php?id=new&equipe_id="+equipe_id+"&membre="+membre_id+"&fonction="+fonction);
	list_responsables(equipe_id);
}

function delete_responsable(equipe_id,membre_id,fonction){
	text = file("responsables_admin.php?equipe_id="+equipe_id+"&membre="+membre_id+"&fonction="+fonction+"&del=1&id=del");
	list_responsables(equipe_id);
}

function check_name(){

	value = $('membre').value;
	text = file("verif_membre.php?value="+value+'&check=1');
	if(text == "<ul><li>---</li></ul>"){
		$('membre').value = "";
		$('membre_id').value = "";
	}
	else {
		$('membre_id').value = text;
	}
}

function check_joueur(){

	value = $('joueur').value;
	text = file("verif_membre.php?value="+value+'&check=1');
	if(text == "<ul><li>---</li></ul>"){
		$('joueur').value = "";
		$('joueur_id').value = "";
	}
	else $('joueur_id').value = text;
}

function check_marqueur1(){

	value = $('marqueur1').value;
	text = file("verif_membre.php?value="+value+'&check=1&marqueur=1');
	if(text == "<ul><li>---</li></ul>"){
		$('marqueur1').value = "";
		$('marqueur1_id').value = "";
	}
	else $('marqueur1_id').value = text;
}
function check_marqueur2(){

	value = $('marqueur2').value;
	text = file("verif_membre.php?value="+value+'&check=1&marqueur=1');
	if(text == "<ul><li>---</li></ul>"){
		$('marqueur2').value = "";
		$('marqueur2_id').value = "";
	}
	else $('marqueur2_id').value = text;
}

function check_arbitre1(){

	value = $('arbitre1').value;
	text = file("verif_membre.php?value="+value+'&check=1&arbitre=1');
	if(text == "<ul><li>---</li></ul>"){
		$('arbitre1').value = "";
		$('arbitre1_id').value = "";
	}
	else $('arbitre1_id').value = text;
}
function check_arbitre2(){

	value = $('arbitre2').value;
	text = file("verif_membre.php?value="+value+'&check=1&arbitre=1');
	if(text == "<ul><li>---</li></ul>"){
		$('arbitre2').value = "";
		$('arbitre2_id').value = "";
	}
	else $('arbitre2_id').value = text;
}


function list_joueurs(id){
	text = file("joueurs_admin.php?equipe="+id);
	writediv(text,'joueurs');
}

function edit_joueur(equipe_id,id){
	text = file("joueurs_admin.php?equipe_id="+equipe_id+"&id="+id+"&action=form");
	if(text){
		var tab = text.split("<!--!>");
		var licence = tab[0];
		var cotisation = tab[1];
		writediv(licence,"licence_"+id);
		writediv(cotisation,"cotisation_"+id);
	}
}

function form_edit_joueur(membre_id,id){
	text = file("joueurs_admin.php?equipe_id="+id);
	if(text){
		var tab = text.split("<!--!>");
		var membre = tab[0];
		var myaction = tab[1];
		writediv(membre,"joueur_new");
		writediv(myaction,"action_joueur_new");
	}
	new Ajax.Autocompleter('joueur', 'autocomplete_choices_joueur', 'verif_membre.php', {paramName: 'value', minChars: 2, indicator: 'indicator1_joueur', afterUpdateElement: check_joueur});
}

function new_joueur(equipe_id,joueur_id){
	text = file("joueurs_admin.php?equipe_id="+equipe_id+"&id="+joueur_id+"&action=add");
	list_joueurs(equipe_id);
}

function delete_joueur(equipe_id, joueur_id){
	text = file("joueurs_admin.php?equipe_id="+equipe_id+"&id="+joueur_id+"&action=del");
	list_joueurs(equipe_id);
}

function form_edit_arbitrage(no_arbitrage,table_row_id){
	text = file("arbitrages_admin.php?match_no="+no_arbitrage+"&action=form&table_row_id="+table_row_id);
	if(text){
		writediv(text,"center_box");
	}
	new Ajax.Autocompleter('salle', 'autocomplete_choices_salles', 'salle.php', {paramName: 'value', minChars: 2, indicator: 'indicator1_salle', afterUpdateElement: check_salle});
	new Ajax.Autocompleter('arbitre1', 'autocomplete_choices_arbitre1', 'verif_membre.php?arbitre=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_arbitre1', afterUpdateElement: check_arbitre1});
	new Ajax.Autocompleter('arbitre2', 'autocomplete_choices_arbitre2', 'verif_membre.php?arbitre=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_arbitre2', afterUpdateElement: check_arbitre2});
	center_box(1);
}

function form_new_arbitrage(){
	text = file("arbitrages_admin.php?action=form");
	if(text){
		writediv(text,"center_box");
	}
	new Ajax.Autocompleter('salle', 'autocomplete_choices_salles', 'salle.php', {paramName: 'value', minChars: 2, indicator: 'indicator1_salle', afterUpdateElement: check_salle});
	new Ajax.Autocompleter('arbitre1', 'autocomplete_choices_arbitre1', 'verif_membre.php?arbitre=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_arbitre1', afterUpdateElement: check_arbitre1});
	new Ajax.Autocompleter('arbitre2', 'autocomplete_choices_arbitre2', 'verif_membre.php?arbitre=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_arbitre2', afterUpdateElement: check_arbitre2});
	center_box(1);
}


function form_edit_match(no_match,table_row_id){
	text = file("matchs_admin.php?no="+no_match+"&action=form&table_row_id="+table_row_id);
	if(text){
		writediv(text,"center_box");
	}
	new Ajax.Autocompleter('salle', 'autocomplete_choices_salles', 'salle.php', {paramName: 'value', minChars: 2, indicator: 'indicator1_salle', afterUpdateElement: check_salle});
	new Ajax.Autocompleter('marqueur1', 'autocomplete_choices_marqueur1', 'verif_membre.php?marqueur=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_marqueur1', afterUpdateElement: check_marqueur1});
	new Ajax.Autocompleter('marqueur2', 'autocomplete_choices_marqueur2', 'verif_membre.php?marqueur=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_marqueur2', afterUpdateElement: check_marqueur2});
	center_box(1);
}

function form_new_match(equipe_id){
	text = file("matchs_admin.php?equipe="+equipe_id+"&action=form");
	if(text){
		writediv(text,"center_box");
	}
	new Ajax.Autocompleter('salle', 'autocomplete_choices_salles', 'salle.php', {paramName: 'value', minChars: 2, indicator: 'indicator1_salle', afterUpdateElement: check_salle});
	new Ajax.Autocompleter('marqueur1', 'autocomplete_choices_marqueur1', 'verif_membre.php?marqueur=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_marqueur1', afterUpdateElement: check_marqueur1});
	new Ajax.Autocompleter('marqueur2', 'autocomplete_choices_marqueur2', 'verif_membre.php?marqueur=1', {paramName: 'value', minChars: 2, indicator: 'indicator1_marqueur2', afterUpdateElement: check_marqueur2});
	center_box(1);
}

function del_match(match_id,row_id){
	text = file("update_match_admin.php?action=del&id="+match_id);
	if(text == 1) message("modification effectu&eacute;e");
	else message ("Désolé, une erreur est survenue");
	if(self.location.href.indexOf("calendrier")){
		update_calendrier($('affichage_matchs').selectedIndex);
	}
	else hide_row_table(match_id,1,'no');
}


function check_salle(){
	value = $('salle').value;
	text = file("salle.php?value="+value+'&check=1');
	if(text == "<ul><li>---</li></ul>"){
		$('salle').value = "";
		$('salle_id').value = "";
	}
	else $('salle_id').value = text;
}

var xmlHttpSalle
function get_salle(no){
	xmlHttpSalle=GetXmlHttpObject()
	if (xmlHttpSalle==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	var url="salle.php";
	url=url+"?map=1&value="+no;
	url=url+"&sid="+Math.random();
	xmlHttpSalle.onreadystatechange=stateChangedSalle;
	xmlHttpSalle.open("POST",url,true);
	xmlHttpSalle.send(null);
}

function stateChangedSalle() {
	if (xmlHttpSalle.readyState==4){
		writediv(xmlHttpSalle.responseText,"center_box");
		center_box(1);
	}
}

function show_salle(salle){
	var content = "<p class = 'center'><iframe frameborder = '0' scrolling = 'no' src = 'salle.php?value="+salle+"&amp;map=1' style = 'height: 600px; width: 500px' name = 'salle_"+salle+"'></iframe></p>";
	writediv(content,'center_box');
	center_box(1,600);
}

function print_calendrier(){
	text = file('calendrier_admin.php?action=print');
	if(text) writediv(text,"calendrier");
}

function update_calendrier(option_value){
	file('calendrier_admin.php?action=update&option='+option_value);
	print_calendrier();
}

function update_resultat(match_no,resultat,origine){
	if(match_no && resultat){
		if(origine == 'calendrier') var id_match = 'id';
		else var id_match = 'match';
		text = file("update_match_admin.php?action=resultat&"+id_match+"="+match_no+"&resultat="+resultat);
		writediv(text,"ok_"+match_no);
	}
}

function print_marquages(admin){
	var url = (admin) ? 'marquages_admin.php' : 'marquages.php';
	new Ajax.Updater('marquages',url,{parameters: {action: 'print'}});
	// if(admin) text = file('marquages_admin.php?action=print');
	// else text = file('marquages.php?action=print');
	// if(text) writediv(text,"marquages");
}

function update_marquages(option_value,admin){
	if(admin) text = file('marquages_admin.php?action=update&option='+option_value);
	else file('marquages.php?action=update&option='+option_value);
	print_marquages(admin);
}

function confirm_marquage(match_no,field,id_membre,admin){
	if(admin) text = file("marquages_admin.php?action=confirm&match_no="+match_no+"&field="+field+"&membre_id="+id_membre);
	else text = file("marquages.php?action=confirm&match_no="+match_no);
	writediv(text,"center_box");
	center_box(1);
}

function add_marquage(match_no,field,id_membre,admin){
	center_box(0);
	if(!admin) text = file("marquages.php?action=add&match_no="+match_no);
	else text = file("marquages_admin.php?action=add&match_no="+match_no+"&field="+field+"&membre_id="+id_membre);
	message(text);
	print_marquages(admin);
}

function detail_marquage(no,admin){
	if(!admin) text = file('marquages.php?match_no='+no+'&action=detail');
	else text = file('marquages_admin.php?match_no='+no+'&action=detail');
	if(text) writediv(text,'center_box');
	center_box(1,0,1);
}

function print_arbitrages(admin){
	if(admin) text = file('arbitrages_admin.php?action=print');
	else text = file('arbitrages.php?action=print');
	if(text) writediv(text,"arbitrages");
}

function update_arbitrages(option_value,admin){
	if(admin) text = file('arbitrages_admin.php?action=update&option='+option_value);
	else file('arbitrages.php?action=update&option='+option_value);
	print_arbitrages(admin);
}

function update_arbitrage(){
	var myform = $('form_arbitrage');
	myform.date.value = myform.annee.value+"-"+myform.mois.value+"-"+myform.djour.value;
	myform.heure.value = myform.heures.value+":"+myform.minute.value+":"+myform.seconde.value;
	if(!myform.arbitre1.value) myform.arbitre1_id.value=0;
	if(!myform.arbitre2.value) myform.arbitre2_id.value=0;
	if(!myform.salle.value) myform.salle_id.value=0;
	$('form_arbitrage').request({
	  method: 'post',
	  onComplete: function(transport){
		var response = transport.responseText || "aucune donn&eacute;e...";
		message(response);
		center_box(0);
		print_arbitrages(1);
	 }
	})
}

function confirm_arbitrage(match_no,field,id_membre,admin){
	if(admin) text = file("arbitrages_admin.php?action=confirm&match_no="+match_no+"&field="+field+"&membre_id="+id_membre);
	else text = file("arbitrages.php?action=confirm&match_no="+match_no);
	writediv(text,"center_box");
	center_box(1);
}

function add_arbitrage(match_no,field,id_membre,admin){
	center_box(0);
	if(!admin) text = file("arbitrages.php?action=add&match_no="+match_no);
	else text = file("arbitrages_admin.php?action=add&match_no="+match_no+"&field="+field+"&membre_id="+id_membre);
	message(text);
	print_arbitrages(admin);
}

function detail_arbitrage(no,admin){
	if(!admin) text = file('arbitrages.php?match_no='+no+'&action=detail');
	else text = file('arbitrages_admin.php?match_no='+no+'&action=detail');
	if(text) writediv(text,'center_box');
	center_box(1,0,1);
	self.location.href = '#top';
}

function del_arbitrage(arbitrage_id,table_name){
	text = file("update_arbitrage_admin.php?action=del&id="+arbitrage_id);
	if(text == 1){
		print_arbitrages(1);
		message("suppression effectu&eacute;e");
	}
	else message ("D&eacute;sol&eacute;, une erreur est survenue");
}



function historique_article(id){
	text = file("historique.php?article="+id);
	writediv(text,"article_historique");
	if($('search_article')){ writediv('','search_article');}
}

function resume_periode(periode){
	text = file("historique_admin.php?action=resume&periode="+periode);
	writediv(text,"action");
}

function update_presse(periode,corps){
	text = file("historique_admin.php?action=update_presse&periode="+periode+"&corps="+corps);
	if(text==1) message("Modifications faite avec succès");
	else message("Désolé, une erreur est survenue");
	resume_periode();
}

function print_presence(equipe,start){
	text = file("equipe_presences.php?equipe="+equipe);
	writediv(text,'presences');
}

function update_presence(membre,match,equipe){
	var left = $("scroll_table").scrollLeft;
	text = file("equipe_presences.php?membre="+membre+"&match="+match);
	print_presence(equipe,0);
	$("scroll_table").scrollLeft = left;
}

function prochain_presences(equipe){
	response = file("equipe_presences.php?equipe="+equipe+"&prochain_presences=1");
	var text = (response==1) ? "tous les matchs" : "prochains matchs";
	$("link_prochain_presences").update(text)
	print_presence(equipe);
}

function update_compta(membre,field,value){
	text = file("compta_admin.php?action=update&membre="+membre+"&field="+field+"&value="+value);
	if(text == 1) message("Modification r&eacute;ussie");
	else message("Désolé, une erreur est survenue");
}

function print_compta(filter){
	text = file("compta_admin.php?action=print&filtre="+filter);
	writediv(text,'action');
}

function info_soutien(){
	text = file("partenaires.php?action=info");
	if(text){
		writediv(text,"center_box");
		center_box(1);
	}
}

function form_soutien(){
	new Ajax.Updater("center_box","partenaires.php",{
		parameters: {action: "form"},
		onComplete: function(){
			center_box(1);
		}
	})
}

function add_field(valeur){
	text = file("activites_admin.php?action=add_field&valeur="+valeur);
	writediv(text,'p_'+valeur);
	var el = $('p_'+valeur);
	el.style.display = 'block';
	el.style.visibility = 'visible';
	var p  = document.createElement('p');
	var n = valeur+1;
	p.setAttribute('id','p_'+n);
	if(!$('p_'+n)) $('champs').appendChild(p);
	writediv("<a style = 'padding-left: 21em;' href = 'javascript:add_field("+n+")'><img src = 'images/icon_plus.png' alt = '+' width = '20' height = '20' /></a>","p_"+n)
}

function del_field(valeur){
	var el = $('p_'+valeur);
	writediv('',el);
	el.style.display = 'none';
	el.style.visibility = 'hidden';
}

function delete_inscription_activite(activite,id){
	var texte = file('activites.php?inscription='+activite+'&action=delete&id_inscription='+id);
	var tab = texte.split("<--->");
	message(tab[1]);
	writediv(tab[0],'inscrits');
}

function update_inscription_activite(activite,id){
	var texte = file("activites.php?inscription="+activite+"&action=update&id_inscription="+id);
	writediv(texte,'inscription');
}

function search(text,admin){
	if(window.mytimeout) window.clearTimeout(window.mytimeout);
 	window.mytimeout = window.setTimeout(function(){
		if(text.length > 2)
		var url = (admin) ? "search_admin.php" : "search.php";
		new Ajax.Request(url,{
			parameters: {search: text,sid: Math.random()},
			onComplete: function(transport){
				var response = transport.responseText || "";
				$('body').update(response);
			}
		})
    },750)
}


function preview_membre(){
	value = $('search_term').value;
	text = file("verif_membre.php?value="+value+'&check=1');
	if(text == "<ul><li>---</li></ul>"){
		$('membre_id').value = "";
	}
	else{
		$('membre_id').value = text;
		show_membre(text);
	}
}

function export_membres(){
	texte = file('membre_admin.php?action=form_export');
	writediv(texte,'action');
}

function export_partenaires(){
	texte = file('partenaires_admin.php?action=form_export');
	writediv(texte,'action');
}


function form_email(){
	texte = file('antispam.php?action=form_cookie');
	writediv(texte,"center_box");
	center_box(1);
}

function check_antispam(value){
	texte = file('antispam.php?action=check&value='+value);
	if(texte == 1) self.location.reload();
	else{
		center_box(0)
		message("D&eacute;sol&eacute;, le code copi&eacute; n'est pas valide")
		texte = file('antispam.php?action=form_cookie');
		writediv(texte,"center_box");
		center_box(1)
	}
}

function print_classement(id){
	texte = file('equipes.php?id='+id+'&classement=1');
	if(texte){
		writediv(texte,'center_box');
		center_box(1,700);
	}
}


function identify_admin(password){
	texte = file("perso.php?action=valide_admin&password="+password);
	if(texte == 1) goBack();
	else{
		message("Mauvais mot de passe");
		self.location.href = 'perso.php?action=admin';
	}
}

function stats_match(match_no){
	texte = file("stats.php?match="+match_no);
	if(texte){
		writediv(texte,'center_box');
		center_box(1);
	}
}

function update_match(){
	var myform = $('form_match');
	myform.date.value = myform.annee.value+"-"+myform.mois.value+"-"+myform.djour.value;
	myform.heure.value = myform.heures.value+":"+myform.minute.value+":"+myform.seconde.value;
	if(!myform.marqueur1.value) myform.marqueur1_id.value=0;
	if(!myform.marqueur2.value) myform.marqueur2_id.value=0;
	if(!myform.salle.value) myform.salle_id.value=0;
	$('form_match').request({
	  method: 'post',

	  onComplete: function(transport){
		var div_content = transport.responseText || "no response text";
		message(div_content);
		center_box(0);
		if(self.location.href.indexOf("calendrier")){
			$('affichage_matchs').selectedIndex = 1;
			update_calendrier("prochains");
		}
		else self.location.reload();
	 }
	})
}



function goBack(){
if (document.referrer.indexOf("vbcll") == -1 || document.referrer.indexOf("admin") == -1)
{
// Pas Bon
	window.location.replace('http://www.vbcll.ch/calendrier_admin.php');
}
else
{
// On revient en arriere
history.go(-1);
}
}


function div_appear(div_id){
	new Effect.Appear($(div_id),{duration:0.3});
}

function div_fade(div_id){
	new Effect.Fade($(div_id),{duration:0.3});
}

function print_jour_from_date(annee,mois,jour){
	var jours = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
	if(annee && mois && jour){
		mois = mois -1;
		var the_date = new Date(annee,mois,jour);
		var jour = the_date.getDay();
		return jours[jour];
	}
	else return "";
}

function print_table_beach(){
	new Ajax.Request('beach.php',
	   {
	     method:'post',
	     parameters: {action: "table"},
	     onSuccess: function(transport){
	         var div_content = transport.responseText || "no response text";
			writediv(div_content,"table_beach");
	     },
	     onFailure: function(){ message('Désolé, une erreur est survenue') }
	   });
}

function beach_submit(){
	$('form_beach').request({
	  method: 'post',
	  onComplete: function(transport){
		var response = transport.responseText || "aucune donn&eacute;e...";
		message(response);
		print_table_beach();
	 }
	})

}

function delete_beach(id){
	new Ajax.Request('beach.php',
	   {
	     method:'post',
	     parameters: {action: "delete",id: id},
	     onSuccess: function(transport){
	         var div_content = transport.responseText || "no response text";
			message(div_content);
			print_table_beach();
	     },
			     onFailure: function(){ message('Désolé, une erreur est survenue') }
		});
}

function show_emails(){
	new Ajax.Request("update_print_table.php",{
		method: "post",
		parameters: {tablename: "equipes",action: "toggle_column_visibility",value: "nom_complet"},
		onSuccess: function(){
			new Ajax.Request("update_print_table.php",{
				method: "post",
				parameters: {tablename: "equipes",action: "toggle_column_visibility",value: "emails"},
				onSuccess: function(){
					update_table(0,"equipes");
					$("show_emails").update(($("show_emails").innerHTML.indexOf('afficher les emails') > -1)?'afficher les noms complets':'afficher les emails');
				}
			})
		}
	})
}


function insert_tweet(equipe_id){
	if($('tweet_'+equipe_id).visible()){
		$('tweet_'+equipe_id).hide();
		$('edit_tweet_'+equipe_id).show();
		$('button_tweet_'+equipe_id).update("<img src = 'images/icon_ok.png' alt = '' height = '14' width = '14' />valider");
	}
	else{
		var texte = $('edit_tweet_'+equipe_id).getValue();
		var response = file("tweet.php?action=update&equipe_id="+equipe_id+"&texte="+texte);
		if(response.indexOf('succ')){
			new Ajax.Request('tweet.php',{
				parameters: {action: "get_last",equipe_id: equipe_id},
				onComplete: function(transport){
					var response2 = transport.responseText || "<span class = 'fade'>Ecrire un (bon) mot (publi&eacute; le mercredi)</span>";
					$('tweet_'+equipe_id).update(response2);
					$('tweet_'+equipe_id).show();
					$('tweet_'+equipe_id).setStyle({display: 'inline'})
					if(transport.responseText) $('edit_tweet_'+equipe_id).value = response2
					else $('edit_tweet_'+equipe_id).value = "";
					$('edit_tweet_'+equipe_id).hide();
					$('button_tweet_'+equipe_id).update("<img src = 'images/icon_edit.png' alt = '' height = '14' width = '14' />modif.");
				}
			})
		}
		message(response);
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function ballons(){
	new Ajax.Updater('action','ballons_admin.php');
}

function update_ballon(match_no,partenaire_id){
	new Ajax.Request('ballons_admin.php',{
		parameters: {action: 'update',match_no: match_no,partenaire_id: partenaire_id},
		onComplete: function(transport){
			var response = transport.responseText || "";
			message(response);
		}
	})
}

function form_m1(match_no){
	var validate = ($("speaker_"+match_no+"_input")) ? 1 : 0;
	new Ajax.Request('matchs_m1_admin.php',{
		parameters: {action: 'form',no: match_no,validate: validate},
		onCreate: function(){
		 	if($('modif_'+match_no)){
				$('modif_'+match_no).src = ($('modif_'+match_no).src.indexOf('edit')>-1) ? $('modif_'+match_no).src.replace("edit","ok") :  $('modif_'+match_no).src.replace("ok","edit");
			}
		},
		onComplete: function(transport){
			var response = transport.responseText || "";
			if(response.indexOf('ERREUR') > -1) message(response);
			else{
				var fields = eval('('+response+')');
				for(field in fields){
					if($(field+"_"+match_no)) $(field+"_"+match_no).update(fields[field]);
					if(fields[field].indexOf('<input') > -1){
						new Ajax.Autocompleter(field+"_"+match_no+"_input", field+"_"+match_no+"_choices", 'suggest_membre.php', {paramName: 'value', minChars: 2, afterUpdateElement: update_match_m1});
					}
				}
				$$('#table_content_matchs input[type="text"]').each(function(input){
					Event.observe(input,'blur',function(){update_match_m1(input,'')})
				})
			}
		}
	})
}

function update_match_m1(inputField,valueField){
	var value = (valueField) ? valueField.innerHTML : inputField.value;
	var tmp = inputField.id.split("_");
	var field = tmp[0];
	var no = tmp[1];
	new Ajax.Request('matchs_m1_admin.php',{
		parameters: {field: field,value: value,no: no,action: 'update'},
		asynchronous: false,
		onComplete: function(transport){
			var text = transport.responseText || "";
			message(text)
		}
	})
}


